
from views.mx.user import users
from views.xl.small import kind
from db_init import db
from flask_migrate import Migrate
from flask import *

app = Flask(__name__)
app.config.from_object(Config)
migrate = Migrate()
# db.init_app(app)
migrate.init_app(app,db)



app.register_blueprint(users,url_prefix='/user')

app.register_blueprint(kind,url_prefix='/kind')

"""
    获取当前请求的url地址
    拿到这个用户的id
    orm 找到这个用户
    获取这个用户的所有角色
    获取这个用户的所有权限
    判定 当前请求地址 在不在这个些权限内
        不在就 返回 make_response('你没权限')

 """

# @app.after_request
# def add_log(response):
#     global uid
#     try:
#         uid = request.args.get('uid') or g.get('uid')
#         if not KeyError:
#             raise
#     except KeyError as e:
#         print(request.url)
#     log = Log(user_id=uid, url=request.url, method=request.method, create_t=arrow.get().int_timestamp)
#     db.session.add(log)
#     db.session.commit()
#     return response




# @app.before_request
# def get_response():
#     url = str(request.url_rule)
#     print(url)
#     id = request.form.get('id')
#     if not id:
#         return '前端传递的数据不完整'
#     user = User.query.filter_by(id=id).first()
#     powers = sum([role.power for role in user.role_id], [])
#     power_lst = [i.url for i in powers]
#     if url not in power_lst:
#         return make_response('你没权限')



if __name__ == "__main__":
    print(app.url_map)
    app.run(host='0.0.0.0', port=5000)
